package com.feidee.data.email.model;

import com.feidee.data.report.constant.Constant;
import com.feidee.data.report.util.JsonUtil;
import com.feidee.data.report.util.SimpleAES;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.util.Map;

public class MysqlDataSource extends DriverManagerDataSource {


  public MysqlDataSource(String dbinfo){
    try {
      Map<String, String> dbMap = JsonUtil.jsonToStrMap(SimpleAES.decrypt(dbinfo.trim(), Constant.MYSQL_DECRYPT_KEY));
      setDriverClassName(dbMap.get("mysql.java.driver.class"));
      setUrl(dbMap.get("mysql.warehouse.url"));
      setUsername(dbMap.get("mysql.warehouse.user"));
      setPassword(dbMap.get("mysql.warehouse.pwd"));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
